package com.xs.shop.common;

import lombok.Data;

@Data
public class Result<T> {
    private Integer status;
    private Integer code;
    private String msg;
    private T data;

    public static <T> Result<T> success(Integer status, Integer code, String msg, T data) {
        Result<T> result = new Result<>();
        result.setStatus(status);
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> success(T data) {
        return success(20000, 20000, "成功", data);
    }

    public static <T> Result<T> success() {
        return success(20000,20000,"成功", null);
    }

    public static <T> Result<T> error(Integer status, Integer code, String msg) {
        Result<T> result = new Result<>();
        result.setStatus(status);
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> error() {
        return error(-1,-1,"失败");
    }
}
